package com.lfg.leetcode.lcp;

import java.util.Arrays;

public class LCP28purchasePlans {

    public static void main(String[] args) {
        System.out.print(purchasePlans(new int[]{2,2,1,9}, 10));
    }

    final static int mod = 1000000007;
    public static int purchasePlans(int[] nums, int target) {
        int ret = 0;
        Arrays.sort(nums);
        int left =0;
        int right = nums.length -1;
        while(right > left){
            while(nums[left] + nums[right] > target){
                right--;
            }
            ret += right-left;
            left++;
        }

        return ret%mod;
    }
}
